﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
namespace IHISCETeim.Web.MachineSys.UserModel
{
    public partial class UWarrantyCardView : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看 };
            }
        }
        protected override string DWZRef
        {
            get { return "UWarrantyCardList"; }
        }

        #region
        /// <summary>
        /// 需要修改的ID
        /// </summary>
        protected int UWCID
        {
            get
            {
                return GetRequestValue<int>("UWCID");
            }
        }

        private UWarrantyCardInfo _obj;
        protected UWarrantyCardInfo obj
        {
            get
            {
                if (_obj == null)
                    _obj = UWarrantyCardController.GetByUWCID(UWCID);
                return _obj;
                //OMenuController.ge
            }
        }

        private List<UQuestionnaireInfo> _listuq;
        protected List<UQuestionnaireInfo> listUQ
        {
            get
            {
                if (_listuq == null)
                    _listuq = UWarrantyCardController.GetUQuestionnaireByUWCID(UWCID);
                return _listuq;
                //OMenuController.ge
            }
        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            AddLog(Permission.查看, obj);
        }

      
        protected string GetIntoSpecial(string item)
        {
            string[] allcheck = obj.IntoSpecial.Split(new char[] { ',' });
            foreach (string i in allcheck)
            {
                if (i == item)
                {
                    return "checked";
                    break;
                }
            }
            return "";
        }

        protected string GetIntoConditi(string item)
        {
            string[] allcheck = obj.IntoConditi.Split(new char[] { ',' });
            foreach (string i in allcheck)
            {
                if (i == item)
                {
                    return "checked";
                    break;
                }
            }
            return "";
        }

        #region 获取调查表模板
        protected string GetUQuestionTemplete()
        {
            string TempHtml = "";
            // TempHtml = UWarrantyCardController.DC.Get<string>(DataCacheKey.UQuestionTempleteDCKey);
            //  if (!TempHtml.IsEmptyOrNull())
            //     return TempHtml;
            TempHtml = "";
            string ItemTmpHtmlTitleTemp = "<b>({0}){1}</b>";
            string ItemTmpHtmlConTemp = "<table>{0}</table><div class=\"divider\"></div> ";
            List<UQuestionTempleteInfo> allQtemp = UWarrantyCardController.GetAllUQuestionTempleteByParId(0);
            foreach (UQuestionTempleteInfo item in allQtemp)
            {
                TempHtml = TempHtml + string.Format(ItemTmpHtmlTitleTemp, item.OrderId, item.Title); ;
                List<UQuestionTempleteInfo> AllitemTemp = UWarrantyCardController.GetAllUQuestionTempleteByParId(item.UQTID);
                string trhtml = "";
                int tdnum = 0;
                // item.RowTDNum = item.RowTDNum+1;
                trhtml = "<tr>";
                foreach (UQuestionTempleteInfo item2 in AllitemTemp)
                {
                    if ((tdnum % item.RowTDNum) == 0 && tdnum != 0)
                    {
                        trhtml = trhtml + "</tr><tr>";
                    }

                    string checkedstr = listUQ.Find(e => e.UQTID == item2.UQTID) == null ? "" : "checked";

                    trhtml = trhtml + string.Format("<td><label><input type=\"checkbox\" name=\"uqt{0}\" value=\"{1}\" {3}>{2}</label></td>", item.UQTID, item2.UQTID, item2.Title, checkedstr);
                    tdnum++;
                }
                trhtml = trhtml + "</tr>";

                TempHtml = TempHtml + string.Format(ItemTmpHtmlConTemp, trhtml);
            }

            //UWarrantyCardController.DC.Add(DataCacheKey.UQuestionTempleteDCKey, TempHtml);
            return TempHtml;
        }
        #endregion
    }
}